	//------------------
	//调试工具
	//------------------	   
   function print(msg) {      
			if (debug) {
	    	$("#debug_div").dialog('open');
	    	debug_html = msg + "<br/>"+debug_html;
	      $("#debug_div").html(debug_html);
	    }
   }
	   
	//------------------
	//创建、读取cookie
	//------------------
	 function createCookie(name,value,days) {
	  if (days) {
	    var date = new Date();
	    date.setTime(date.getTime()+(days*24*60*60*1000));
	    var expires = "; expires="+date.toGMTString();
	  }
	  else expires = "";
	  document.cookie = name+"="+value+expires+"; path=/; domain=gmodules.com";
	 };

	 function readCookie(name) {
	  var nameEQ = name + "=";
	  var ca = document.cookie.split(';');
	  for(var i=0;i < ca.length;i++) {
	    var c = ca[i];
	    while (c.charAt(0)==' ') c = c.substring(1,c.length);
	    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	  }
	  return null;
	 };

	//------------------
	//翻译
	//------------------
	String.prototype.t = function (){
	                            var str;
	                            if(oPrefs.getMsg(this)!=""){
	                            str=oPrefs.getMsg(this)
	                            }else{
	                            str=this;
	                            }
	                            return str;
	 }

	//------------------
	//判断气温的颜色
	//------------------
	function tempalert(temp){
		var color="";
		var r=255;
		var g=255;
		var b=145;
		if(temp<0){
			b=15*(0-temp);
			if(b>255){
			  b=255;
			}
		}else{
		   for(var i=0;i<temp;i++){
		     b=b-15;
		   }
		   if(b<0){
		      g=b+255;
		      b=0;
		      if(g<0){
		         r=g+255;
		         g=0;
		         if(r<150){r=150;}
		      }
		   }
		}
		color="rgb("+new String(r)+","+new String(g)+","+new String(b)+")";
		return color;
	 }
	//------------------
	//判断白天黑夜
	//------------------
	function fnTN(sunr,suns){
	  var nowdate = Math.round((new Date().getTime())/1000);
	  if(nowdate>suns){
	    return false;
	  }else{
	    return true;
	  }
	 }

	//------------------
	//关闭地图
	//------------------
	function fnCloseMap(){
	         $("#maps").html("");
	         $("#maps").css("display","none");	
	         $("#mapsclose").css("display","none");	
	         map = null;
	}
	
	//------------------
	//显示地图
	//------------------
	function CoordMapType(tileSize,lid) {
		this.tileSize = tileSize;
		this.maplayer = lid;
		this.name = "Weather";
		this.alt = "Weather";
		this.T = [];
		this.getTile = function(coord, zoom, ownerDocument) {
			var div = ownerDocument.createElement('IMG');
			//$("#map-update-info").html(chrome.i18n.getMessage("loading"));
			div.style.width = this.tileSize.width + 'px';
			div.style.height = this.tileSize.height + 'px';
			//div.style.opacity = opa;
			div.src = 'http://tiles.weatherbug.com/DataService/GetTile_v2.aspx?pid=2c6564fb-dc4c-422c-b89a-e7d4d4f4890b&cid=60016002&lid='+this.maplayer+'&stl=0&as=0&c=0&fq=1&tx='+coord.x+'&ty='+coord.y+'&zm='+zoom;
			if(this.maplayer=="88"){
				div.style.opacity = 1;
				div.src = 'http://mt2.google.com/mapslt?lyrs=weather_c_kph|invert:1&x='+coord.x+'&y='+coord.y+'&z='+zoom+'&w=256&h=256&hl=zh-CN';
			}
			if(this.maplayer=="47"){
				div.style.opacity = 1;
				div.src = 'http://mt0.google.com/vt/lyrs=h@162000000,weather_nolabels,weather_0cloud&hl=zh-CN&x='+coord.x+'&y='+coord.y+'&z='+zoom+'&s=Galileo';
			}
			div.onload = function() {
				//$("#map-update-info").html("");
			}
			this.T.push(div);
			return div;
		};
	}
	
	function fnShowMap(){
	         $("#maps").css("display","block");	
	         $("#maps").height(290);	
	         $("#maps").width($("#copyright").width()-1);
	         $("#mapsclose").css("display","inline");	

					var nowLatLng = new google.maps.LatLng(iCurrenLat,iCurrenLon);
					//var coordinateMapType = new CoordMapType(new google.maps.Size(256, 256),"11");
					var mapOptions = {
						zoom: 6,
						center: nowLatLng,
						streetViewControl: false,
						mapTypeId: google.maps.MapTypeId.SATELLITE,
						}
					map = new google.maps.Map(document.getElementById('maps'),mapOptions);
									
				  //var homeControlDiv = document.createElement('DIV');
				  //var homeControl = new HomeControl(homeControlDiv);
				  //var opacityControlDiv = document.createElement('DIV');
				  //var opacityControl = new OpacityControl(opacityControlDiv);
				
				  //homeControlDiv.index = 2;
				  //opacityControlDiv.index = 1;
				  //map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv);
				  //map.controls[google.maps.ControlPosition.TOP_RIGHT].push(opacityControlDiv);
				  
				  map.overlayMapTypes.setAt(2, new CoordMapType(new google.maps.Size(256, 256),"88")); 
	 }
/*	 
	//------------------
	//在地图查询城市
	//------------------
	function fnGetMarkers(){
	         
	         Loadingstart();
	         map.clearOverlays();
	         url = "http://www.dnxh.cn/gadgets/weather/Markers.asp?BBOX=" + map.getBounds().getSouthWest().lng()+ "," + map.getBounds().getSouthWest().lat()+ "," + map.getBounds().getNorthEast().lng()+ "," + map.getBounds().getNorthEast().lat();
	         _IG_FetchXmlContent(url,function (response){
	                                        if (response == null || typeof(response) != "object" || 
	                                                  response.firstChild == null) {
	                                                   fnOpenMsg(oPrefs.getMsg("ResponseErr"));
	                                                   Loadingend();
	                                                   return;
	                                        }
	                                        
	               var oicon = new GIcon();
	               oicon.image = "http://myweather.googlecode.com/svn/trunk/images/icon/"+iCurrenIcon+"s.png";
	               oicon.iconSize = new GSize(61,34);
	               oicon.iconAnchor = new GPoint(30.5,17);
	               
	               var oNowPt = new Object();
	               oNowPt.icon=oicon;
	               oNowPt.title=aCityNames[iCurrenCityId];
	               
	               var point_marker = new GMarker(new GLatLng(iCurrenLat,iCurrenLon), oNowPt);
	               
	               map.addOverlay(point_marker);
	                                        
	                                        var icon = new GIcon();
		                                    icon.image = "http://labs.google.com/ridefinder/images/mm_20_blue.png";
		                                    icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		                                    icon.iconSize = new GSize(12, 20);
	                                        icon.shadowSize = new GSize(22, 20);
	                                        icon.iconAnchor = new GPoint(6, 20);
	                                        icon.infoWindowAnchor = new GPoint(5, 1);
	                                        var opt=new Object();
	                                        
	                                        opt.icon = icon;
	    
	                                        var markers = response.getElementsByTagName("marker");
	                                        for(i=0;i<markers.length;i++){
	                                              var lat = markers[i].getAttribute("lat");
	                                              var lng = markers[i].getAttribute("lng");
	                                              var title = markers[i].getAttribute("name");
	                                              var code = markers[i].getAttribute("code");
	                                              var id = markers[i].getAttribute("index");
	                                              if(id!=-1){
	                                                var nIndex=indexof(code);
	                                                if(nIndex==undefined){
	                                              opt.title = title;
	                                              var newMarker = new GMarker(new GLatLng(lat,lng),opt);
	                                              GEvent.addListener(newMarker,"click",
	                                                      getClickCallBack(title,code)
	                                              );
	                                              map.addOverlay(newMarker);
	                                              }
	                                              }
	                                              }
	                                              Loadingend();
	                                        })


	 }
		function getClickCallBack(title,code) 
			{ 
			        return function(){
			        fnOpenMsg(oPrefs.getMsg('citys')+"<b>"+title+"</b> ? "+"<input onclick='fnAddCity(\""+title+"\",\""+code+"\");fnCloseMsg()' type='button' id='add' value='"+oPrefs.getMsg('UIgo')+"'/>")
			        } ;
			}
*/
	//------------------
	//单位设置
	//------------------
	function fnUnit(str){
	         if(str=="s"){
	           sUnit="s";
	           oPrefs.set("unit", "s");
	           createCookie("GadgetWeatherbyDnxh.cn",aCityNames.join("|")+"||"+aCityCodes.join("|")+"||"+sUnit,365);
	           fnLoadWeatherData(aCityCodes[iCurrenCityId]);
	         }else{
	           sUnit="m";
	           oPrefs.set("unit", "m");
	           createCookie("GadgetWeatherbyDnxh.cn",aCityNames.join("|")+"||"+aCityCodes.join("|")+"||"+sUnit,365);
	           fnLoadWeatherData(aCityCodes[iCurrenCityId]);
	         }
	 }
  //------------------
  //颜色设置
  //------------------
  function hex2rgb(hex) {	
		var rgb = new Array();
			rgb[0]=parseInt(hex.substr(1, 2), 16);
			rgb[1]=parseInt(hex.substr(3, 2), 16);
			rgb[2]=parseInt(hex.substr(5, 2), 16);
			return rgb;
	}
	function hexFromRGB (r, g, b) {
		var hex = [
			r.toString(16),
			g.toString(16),
			b.toString(16)
		];
		$.each(hex, function (nr, val) {
			if (val.length == 1) {
				hex[nr] = '0' + val;
			}
		});
		return hex.join('').toUpperCase();
	}
	function refreshSwatch() {
		var red = $("#red").slider("value")
			,green = $("#green").slider("value")
			,blue = $("#blue").slider("value")
			,hex = hexFromRGB(red, green, blue);
		$("#"+FocusColor).css("background-color", "#" + hex);
		if(FocusColor == "fcolor"){$("#panel,a,td").css("color", "#" + hex);};
		if(FocusColor == "tcolor"){$(".d").css("background-color", "#" + hex);};
		if(FocusColor == "ncolor"){$(".n").css("background-color", "#" + hex);};
	}
	function fnSaveColors(){
		$("#"+FocusColor+"save").removeClass("ui-state-hidden");
		$("#"+FocusColor+"save").removeClass("ui-icon-check");
		$("#"+FocusColor+"save").addClass("ui-save-icon");
	}
	function colorslider(r,g,b){
		$("#red, #green, #blue").slider({
			orientation: 'horizontal',
			range: "min",
			max: 255,
			value: 127,
			slide: refreshSwatch,
			change: fnSaveColors
		});
		$("#red").slider("value", r);
		$("#green").slider("value", g);
		$("#blue").slider("value", b);
		$("#"+FocusColor+"save").addClass("ui-state-hidden");
	}
	//------------------
	//查找索引
	//------------------
	function indexof(code){
	         var i;
	             for(i=0;i<aCityCodes.length;i++){
	                if(aCityCodes[i]==code)
	                return i;
	             }
	 }

	//------------------
	//设置默认城市
	//------------------
	function fnMakeDefaultCity(code){
	         var id=indexof(code);
	         var DefCityCode = aCityCodes[id];
	         var DefCityName = aCityNames[id];
	         
	         aCityNames.splice(id,1);
	         aCityCodes.splice(id,1);
	         aCityNames.unshift(DefCityName);
	         aCityCodes.unshift(DefCityCode);
	              
	         //城市列表
	         var headHTML="<ul id=\"NowCityList\">";
	             for(i=0;i<aCityNames.length;i++){
	                 if(i==0){
	                 headHTML += "<li class=\"controloff\" onmouseover=\"this.className='controlon'\" onmouseout=\"this.className='controloff'\">"+aCityNames[i]+"<span><a class=\"nowcitylist\" title=\""+oPrefs.getMsg("UIdelete")+"\" onclick=\"fnDelCity('"+aCityCodes[i]+"')\">"+oPrefs.getMsg("UIdelete")+"</a></span><em>(Default Location)</em></li>";
	                 }else{
	                 headHTML += "<li class=\"controloff\" onmouseover=\"this.className='controlon'\" onmouseout=\"this.className='controloff'\">"+aCityNames[i]+"<span><a class=\"nowcitylist\" title=\""+oPrefs.getMsg("UImakedefaultcity")+"\" onclick=\"fnMakeDefaultCity('"+aCityCodes[i]+"')\">"+oPrefs.getMsg("UImakedefaultcity")+"</a>|<a class=\"nowcitylist\" title=\""+oPrefs.getMsg("UIdelete")+"\" onclick=\"fnDelCity('"+aCityCodes[i]+"')\">"+oPrefs.getMsg("UIdelete")+"</a></span></li>";
	                 }
	             }
	             headHTML+="</ul>";
	            _gel("delcitys").innerHTML="<h4>My Saved Locations</h4>"+headHTML;
	            
	            oPrefs.set("cityname", aCityNames.join("|"));
	            oPrefs.set("citycode", aCityCodes.join("|"));
	              
	              //写入Cookie
	            createCookie("GadgetWeatherbyDnxh.cn",aCityNames.join("|")+"||"+aCityCodes.join("|")+"||"+sUnit,365);
	          return false;
	 }
	 
	//------------------
	//删除城市
	//------------------
	function fnDelCity(code){
	         if(aCityCodes.length==1){
	              fnOpenMsg("<b>"+oPrefs.getMsg("MSGminCity")+"</b>");
	         }else if(code==aCityCodes[iCurrenCityId]){
	         
	              var headHTML="";
	              var id=indexof(code);
	              aCityNames.splice(id,1);
	              aCityCodes.splice(id,1);
	              
	              for(i=0;i<aCityNames.length;i++){
	                 if(i==0){
	                 headHTML += "<li class=\"controloff\" onmouseover=\"this.className='controlon'\" onmouseout=\"this.className='controloff'\">"+aCityNames[i]+"<span><a class=\"nowcitylist\" title=\""+oPrefs.getMsg("UIdelete")+"\" onclick=\"fnDelCity('"+aCityCodes[i]+"')\">"+oPrefs.getMsg("UIdelete")+"</a></span><em>(Default Location)</em></li>";
	                 }else{
	                 headHTML += "<li class=\"controloff\" onmouseover=\"this.className='controlon'\" onmouseout=\"this.className='controloff'\">"+aCityNames[i]+"<span><a class=\"nowcitylist\" title=\""+oPrefs.getMsg("UImakedefaultcity")+"\" onclick=\"fnMakeDefaultCity('"+aCityCodes[i]+"')\">"+oPrefs.getMsg("UImakedefaultcity")+"</a>|<a class=\"nowcitylist\" title=\""+oPrefs.getMsg("UIdelete")+"\" onclick=\"fnDelCity('"+aCityCodes[i]+"')\">"+oPrefs.getMsg("UIdelete")+"</a></span></li>";
	                 }
	              }
	              
	              _gel("NowCityList").innerHTML=headHTML;
	              oPrefs.set("cityname", aCityNames.join("|"));
	              oPrefs.set("citycode", aCityCodes.join("|"));
	              
	              //写入Cookie
	              createCookie("GadgetWeatherbyDnxh.cn",aCityNames.join("|")+"||"+aCityCodes.join("|")+"||"+sUnit,365);
	              
	              fnLoadWeatherData(aCityCodes[0]);
	         
	         }else{
	              var headHTML="";
	              var id=indexof(code);
	              aCityNames.splice(id,1);
	              aCityCodes.splice(id,1);
	              
	              for(i=0;i<aCityNames.length;i++){
	                 if(i==0){
	                 headHTML += "<li class=\"controloff\" onmouseover=\"this.className='controlon'\" onmouseout=\"this.className='controloff'\">"+aCityNames[i]+"<span><a title=\""+oPrefs.getMsg("UIdelete")+"\" onclick=\"fnDelCity('"+aCityCodes[i]+"')\">"+oPrefs.getMsg("UIdelete")+"</a></span><em>(Default Location)</em></li>";
	                 }else{
	                 headHTML += "<li class=\"controloff\" onmouseover=\"this.className='controlon'\" onmouseout=\"this.className='controloff'\">"+aCityNames[i]+"<span><a title=\""+oPrefs.getMsg("UImakedefaultcity")+"\" onclick=\"fnMakeDefaultCity('"+aCityCodes[i]+"')\">"+oPrefs.getMsg("UImakedefaultcity")+"</a>|<a title=\""+oPrefs.getMsg("UIdelete")+"\" onclick=\"fnDelCity('"+aCityCodes[i]+"')\">"+oPrefs.getMsg("UIdelete")+"</a></span></li>";
	                 }
	              }
	              
	              _gel("NowCityList").innerHTML=headHTML;
	              oPrefs.set("cityname", aCityNames.join("|"));
	              oPrefs.set("citycode", aCityCodes.join("|"));
	              
	              //写入Cookie
	              createCookie("GadgetWeatherbyDnxh.cn",aCityNames.join("|")+"||"+aCityCodes.join("|")+"||"+sUnit,365);
	         }
	         return false;
	 }

	//------------------
	//添加城市
	//------------------
	function fnAddCity(name,code){
	         if(indexof(code)>=0){
	                    fnOpenMsg("<b>"+oPrefs.getMsg("MSGExisCity")+"</b>");
	                    return;
	         }
	         
	         var headHTML="";
	         aCityNames.push(name);
	         aCityCodes.push(code);
	         if(_gel("NowCityList")){
	         for(i=0;i<aCityNames.length;i++){
	                 if(i==0){
	                 headHTML += "<li class=\"controloff\" onmouseover=\"this.className='controlon'\" onmouseout=\"this.className='controloff'\">"+aCityNames[i]+"<span><a class=\"nowcitylist\" title=\""+oPrefs.getMsg("UIdelete")+"\" onclick=\"fnDelCity('"+aCityCodes[i]+"')\">"+oPrefs.getMsg("UIdelete")+"</a></span><em>(Default Location)</em></li>";
	                 }else{
	                 headHTML += "<li class=\"controloff\" onmouseover=\"this.className='controlon'\" onmouseout=\"this.className='controloff'\">"+aCityNames[i]+"<span><a class=\"nowcitylist\" title=\""+oPrefs.getMsg("UImakedefaultcity")+"\" onclick=\"fnMakeDefaultCity('"+aCityCodes[i]+"')\">"+oPrefs.getMsg("UImakedefaultcity")+"</a>|<a class=\"nowcitylist\" title=\""+oPrefs.getMsg("UIdelete")+"\" onclick=\"fnDelCity('"+aCityCodes[i]+"')\">"+oPrefs.getMsg("UIdelete")+"</a></span></li>";
	                 }
	         }
	         _gel("NowCityList").innerHTML=headHTML;
	         }
	         oPrefs.set("cityname", aCityNames.join("|"));
	         oPrefs.set("citycode", aCityCodes.join("|"));
	         
	         //写入Cookie
	         createCookie("GadgetWeatherbyDnxh.cn",aCityNames.join("|")+"||"+aCityCodes.join("|")+"||"+sUnit,365);
	 }

	//------------------
	//查询城市代码
	//------------------
	function fnSearchCity(){
	         //if(aCityNames.length>2){fnOpenMsg("display weather data for no more than three (3) locations at a time !");return false;}
	         var newcity=_gel("new_name").value;
	         Loadingstart();
	         _IG_FetchXmlContent(
	                            "http://xoap.weather.com/search/search?where="+_esc(newcity), 
	                            function (xml){
	                                     var locs=xml.getElementsByTagName("loc");
	                                     if(locs.length>0){
	                                          if(locs.length==1){
	                                              fnAddCity(xml.getElementsByTagName("loc")[0].firstChild.nodeValue,xml.getElementsByTagName("loc")[0].getAttribute("id"));
	                                          }else{
	                                              var html="";
	                                                  html+="<b>"+oPrefs.getMsg("citysmsg")+"</b>";
	                                                  html+="<ul>";
	                                                  for(i=0;i<locs.length;i++){
	                                                  html+="<li class=\"controloff\" onmouseover=\"this.className='controlon'\" onmouseout=\"this.className='controloff'\" ><a onclick=\"fnAddCity('"+xml.getElementsByTagName("loc")[i].firstChild.nodeValue+"','"+xml.getElementsByTagName("loc")[i].getAttribute("id")+"');this.parentNode.style.display='none';return false\">"+xml.getElementsByTagName("loc")[i].firstChild.nodeValue+"</a></li>";
	                                                  }
	                                                  html+="</ul>";
	                                                  
	                                                  fnOpenMsg(html);
	                                               }
	                                     }else{
	                                           fnOpenMsg("<b>"+oPrefs.getMsg("nocity")+"</b>");
	                                     }
	                                     Loadingend();
	                                     
	                            })
	          return false;
	 }

	//------------------
	//关闭消息框
	//------------------
	function fnCloseMsg(){
	         _gel("msgtext").innerHTML="";
	         _gel('msg').style.display='none';        
	 }

	//------------------
	//显示消息框
	//------------------
	function fnOpenMsg(t){
	         $(".popupbox").width($("#copyright").width());
	         $("#msgtext").html(t);
           $("#msg").css("display","block");
	         Loadingend();
	 }

	//------------------
	//关闭用户设置
	//------------------
	function fnCloseSetting(){
	         // 关闭设置框
	         _gel('setting').style.display='none'; 
		       $("#panel,a,td").css("color", "");
		       $(".d").css("background-color", "");
		       $(".n").css("background-color", "");      
	 }

	//------------------
	//打开用户设置
	//------------------
	function fnOpenSetting(){
	         $(".popupbox").width($("#copyright").width());
	         if(_gel("setting").style.display!="block"){
	         //显示编辑模块
	         _gel("setting").style.display="block";
	                  
	         if(sUnit=="m"){
	             _gel("radio_m").checked=true;
	         }else{
	             _gel("radio_s").checked=true;
	         }

	         //城市列表

	         var headHTML="<ul id=\"NowCityList\">";
	             for(i=0;i<aCityNames.length;i++){
	                 if(i==0){
	                 headHTML += "<li class=\"controloff\" onmouseover=\"this.className='controlon'\" onmouseout=\"this.className='controloff'\">"+aCityNames[i]+"<span><a class=\"nowcitylist\" title=\""+oPrefs.getMsg("UIdelete")+"\" onclick=\"fnDelCity('"+aCityCodes[i]+"')\">"+oPrefs.getMsg("UIdelete")+"</a></span><em>(Default Location)</em></li>";
	                 }else{
	                 headHTML += "<li class=\"controloff\" onmouseover=\"this.className='controlon'\" onmouseout=\"this.className='controloff'\">"+aCityNames[i]+"<span><a class=\"nowcitylist\" title=\""+oPrefs.getMsg("UImakedefaultcity")+"\" onclick=\"fnMakeDefaultCity('"+aCityCodes[i]+"')\">"+oPrefs.getMsg("UImakedefaultcity")+"</a>|<a class=\"nowcitylist\" title=\""+oPrefs.getMsg("UIdelete")+"\" onclick=\"fnDelCity('"+aCityCodes[i]+"')\">"+oPrefs.getMsg("UIdelete")+"</a></span></li>";
	                 }
	             }
	             headHTML+="</ul>";
	            _gel("delcitys").innerHTML="<h4>My Saved Locations</h4>"+headHTML;
    colorslider(255,255,255);
		$("#fcolor,#ncolor,#tcolor").css("background-color", "");
		$(".colorblock").css("border-color","");
		FocusColor = "fcolor";
    $("#fcolor").click(function(){FocusColor = "fcolor";
    	                            $(".colorblock").css("border-color","");
    	                            $("#fcolor").css("border-color","#FFCC33");
    	                            var Argb=($("#fcolor").css("background-color").substr(0, 1) != "#")?$("#fcolor").css("background-color").replace(/\(/,"").replace(/\)/,"").replace("rgb","").split(","):hex2rgb($("#fcolor").css("background-color"));
    	                            colorslider(Argb[0]*1,Argb[1]*1,Argb[2]*1);
    	                            });
    $("#ncolor").click(function(){FocusColor = "ncolor";
    	                            $(".colorblock").css("border-color","");
    	                            $("#ncolor").css("border-color","#FFCC33");
    	                            var Argb=($("#ncolor").css("background-color").substr(0, 1) != "#")?$("#ncolor").css("background-color").replace(/\(/,"").replace(/\)/,"").replace("rgb","").split(","):hex2rgb($("#ncolor").css("background-color"));
    	                            colorslider(Argb[0]*1,Argb[1]*1,Argb[2]*1);
    	                            });
    $("#tcolor").click(function(){FocusColor = "tcolor";
    	                            $(".colorblock").css("border-color","");
    	                            $("#tcolor").css("border-color","#FFCC33");
    	                            var Argb=($("#tcolor").css("background-color").substr(0, 1) != "#")?$("#tcolor").css("background-color").replace(/\(/,"").replace(/\)/,"").replace("rgb","").split(","):hex2rgb($("#tcolor").css("background-color"));
    	                            colorslider(Argb[0]*1,Argb[1]*1,Argb[2]*1);
    	                            });
    $("#tcolorsave").click(function(){$("#tcolorsave").addClass("ui-icon-check");$("#tcolorsave").removeClass("ui-save-icon");});
    $("#ncolorsave").click(function(){$("#ncolorsave").addClass("ui-icon-check");$("#ncolorsave").removeClass("ui-save-icon");});
    $("#fcolorsave").click(function(){$("#fcolorsave").addClass("ui-icon-check");$("#fcolorsave").removeClass("ui-save-icon");});
	         }else{
	         fnCloseSetting();
	         }      
	}

	//------------------
	//插入数据到DOM
	//------------------
	function fnSetContent(d){
	         jsonData = (eval("("+d+")"))[0];
	         var data = jsonData;
	         
        	 iCurrenLat = data.Location.lat;
        	 iCurrenLon = data.Location.lng;
	         _gelstn("h1")[0].firstChild.nodeValue=data.StandardObservation.text.t();
	         _gel("Ctmp").innerHTML=data.StandardObservation.temp;
	         if(sUnit=="s"){
	         _gel("temp").style.color=tempalert(data.StandardObservation.temp);
	         _gel("us").innerHTML="mph";
	         }else{
	         _gel("temp").style.color=tempalert((data.StandardObservation.temp-32)*5/9);
	         _gel("us").innerHTML="km/h";
	         }
	         
	         _gel("Cdewp").innerHTML=data.StandardObservation.dewPoint;
	         _gel("Cflik").innerHTML=data.StandardObservation.feelsLike;
	         _gel("tempicon").setAttribute("src","http://myweather.googlecode.com/svn/trunk/images/icon/"+data.StandardObservation.wxIcon+"d.png");
	         _gel("tempicon").setAttribute("alt",data.StandardObservation.text.t());
	         _gel("CWindt").innerHTML=data.StandardObservation.wDirText.t();
	         _gel("CWinds").innerHTML=data.StandardObservation.wSpeed;
	         _gel("Chmid").innerHTML=data.StandardObservation.humid;
	         
	         if(data.StandardObservation.visibility!="Unlimited"){
	         _gel("Cvis").innerHTML=data.StandardObservation.visibility;
	         _gel("ud").innerHTML="km/h";
	         }else{
	         _gel("Cvis").innerHTML=(data.StandardObservation.visibility+"").t();
	         _gel("ud").innerHTML="";
	         }
	         
	         _gel("CUvi").innerHTML=data.StandardObservation.uv;
	         var ccdate = new Date(parseInt(data.StandardObservation.date) * 1000);
	         _gel("Clsup").innerHTML=ccdate.getFullYear()+"/"+(ccdate.getMonth()+1)+"/"+ccdate.getDate()+" "+ccdate.getHours()+":"+ccdate.getMinutes();
	         
	         //----天气预报----
	         var dayfdata = [];
	         var days = data.DailyForecasts;         
	         for(i=0;i<days.length;i++){
	         		var d = new Date(parseInt(days[i].validDate) * 1000);
	         		if(days[i].day){
	               var html ='<div id="day'+i+'" class="dayn"><span title="' + d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear() + '">' + ('WEEK'+d.getDay()).t() + '</span><br/><div onclick="this.style.display=\'none\';this.nextSibling.style.display=\'block\';this.parentNode.className=\'dayn n\';"><img border="0" alt="'+days[i].day.phrase.t()+'" src="http://myweather.googlecode.com/svn/trunk/images/icon/'+days[i].day.icon+'s.png" title="'+days[i].day.phrase.t()+'"><br/></div><div class="partn" onclick="this.style.display=\'none\';this.previousSibling.style.display=\'block\';this.parentNode.className=\'dayn d\';"><img border="0" alt="'+days[i].night.phrase.t()+'" src="http://myweather.googlecode.com/svn/trunk/images/icon/'+days[i].night.icon+'s.png" title="'+days[i].night.phrase.t()+'"><br/></div>'+oPrefs.getMsg("WDFhi")+(days[i].maxTemp?(days[i].maxTemp+''):'--')+'°<br/>'+oPrefs.getMsg('WDFlow')+(days[i].minTemp?(days[i].minTemp+''):'--')+'°</div>';
	               dayfdata.push(html);
	             }else{
	             	 var html ='<div id="day'+i+'" class="dayn"><span title="' + d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear() + '">' + ('WEEK'+d.getDay()).t() + '</span><br/><div><img border="0" alt="'+days[i].night.phrase.t()+'" src="http://myweather.googlecode.com/svn/trunk/images/icon/'+days[i].night.icon+'s.png" title="'+days[i].night.phrase.t()+'"><br/></div>'+oPrefs.getMsg("WDFhi")+(days[i].maxTemp?(days[i].maxTemp+''):'--')+'°<br/>'+oPrefs.getMsg("WDFlow")+(days[i].minTemp?(days[i].minTemp+''):'--')+'°</div>';
	               dayfdata.push(html);
	             }
	         }
	         
	         dayfdata.push('<div style="clear: both"></div>');
	         _gel("Container").innerHTML=dayfdata.join("");
	         
		         var ss = data.SunRiseSet;
		         var rdate = new Date(parseInt(ss[0].rise) * 1000);
		         var sdate = new Date(parseInt(ss[0].set) * 1000);
		         _gel("sunr").innerHTML=rdate.getHours()+":"+rdate.getMinutes();
	         	 _gel("suns").innerHTML=sdate.getHours()+":"+sdate.getMinutes();

		         //-----面板颜色----	         
		         if(fnTN(ss[0].rise,ss[0].set)){
		               _gel("panel").className="d";
		               _gel("msg").className="d popupbox";
		               _gel("urlary").className="d popupbox";
		               _gel("setting").className="d popupbox";
		               
		         }else{
		               _gel("panel").className="n";
		               _gel("msg").className="n popupbox";
		               _gel("urlary").className="n popupbox";
		               _gel("setting").className="n popupbox";  
		         }
	         	                     
	 }

//------------------
//
//------------------
function fnSlider(){
		//$("#ScrollerHour table").height();
		$("#slider-vertical").slider({
			orientation: "vertical",
			range: "min",
			min: 0,
			max: $("#ScrollerHour table").height()-240,
			value: $("#ScrollerHour table").height(),
			slide: function(event, ui) {
				$("#ScrollerHour .Scroller-Container").css("top",0-($("#ScrollerHour table").height()-240-ui.value)+"px");
			}
		});
}
	//------------------
	//获得24小时天气预报数据
	//------------------
	function fnLoad24Weather(){
		var aHours = jsonData.HourlyForecasts;
		var sHourHtml = [];
		
		for(i=0;i<aHours.length;i++){
			//var str='<div id="dayn"><span>'+aHours[i].c+':00</span><br/><img border="0" alt="'+aHours[i].t+'" src="http://myweather.googlecode.com/svn/trunk/images/icon/'+aHours[i].icon+'s.png" title="'+aHours[i].t+'"><br/>'+aHours[i].tmp+'°|'+aHours[i].hmid+'%<br/>'+aHours[i].Wt+' '+aHours[i].Ws+' '+("U"+oHourData.us).t()+'</div>';
			var str='<tr><td class="hh">'+(new Date(parseInt(aHours[i].dateTime) * 1000)).getHours()+':00</td><td class="hicon"><img border="0" alt="'+aHours[i].wDesc.t()+'" src="http://myweather.googlecode.com/svn/trunk/images/icon/'+aHours[i].icon+'s.png" title="'+aHours[i].wDesc.t()+'"></td><td class="htmp">'+aHours[i].temp+'°</td><td class="hhmin">'+aHours[i].humid+'%</td><td class="hwt">'+aHours[i].wDirText+'</td><td class="hws">'+aHours[i].wSpeed+'</td></tr>'
			sHourHtml.push(str);
		}
		var htext = '<div class="Container"><table style="text-align:center;" width="100%"><tr><td class="hh"> </td><td class="hicon"> </td><td class="htmp">'+((sUnit=='m')?'C°':'F°')+'</td><td class="hhmin">HMIN</td><td class="hwt">WIND</td><td class="hws">'+((sUnit=='m')?'kmh':'mph')+'</td></tr></table>';
		htext += '<div id="ScrollerHour"><div class="Scroller-Container"><table style="text-align:center;" width="100%">'+sHourHtml.join("")+'</table></div></div></div><div id="slider-vertical"></div></div>';
		fnOpenMsg(htext);
		Loadingend();
		fnSlider();
	 }

function makeCachedRequest(url, callback, params, refreshInterval) {
	var ts = new Date().getTime();
	var sep = "?";
	if (refreshInterval && refreshInterval > 0) {
		ts = Math.floor(ts / (refreshInterval * 1000));
	}
	if (url.indexOf("?") > -1) {
		sep = "&";
	}
	url = [ url, sep, "nocache=", ts ].join("");
	gadgets.io.makeRequest(url, callback, params);
}

//------------------
//获取并载入气象数据
//------------------
function fnLoadWeatherData(code){
	         //初始化
	         $("#maps").html("");
	         $("#maps").css("display","none");	
	         $("#mapsclose").css("display","none");	
	         $("#swa").css("display","none");
	         if(80*sDays>$("#copyright").width())$("#Bright").css("display","block");	
	         fnCloseMsg();
	         sTemp="";
	         iCurrenCityId=indexof(code);
	         Loadingstart();
	         //Ajax load
			 var refreshInterval = 60*30;
			 var params = {}; 
			 params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
			 var url = "http://wxdata.weather.com/wxdata/mobile/mobagg/"+code+".js?key=e88d1560-a740-102c-bafd-001321203584&units="+sUnit;
			 print(url);
	         makeCachedRequest(url, function (obj){
								fnSetContent(obj.data);
																		            
								///当前链接
								$("#nowcity").html(aCityNames[iCurrenCityId]);
								$("#urlary").html("");
								$("#urlary").css("display","none");	                                       
								//load stop
								Loadingend();
				                                       
								//兼容IE6-的PNG图片通透
								try{correctPNG()}catch(err){}  
								$(".partn").css("display","none");
								gadgets.window.adjustHeight($("#panel").height());                                
					},params,30 * 60)

					var aName=aCityNames[iCurrenCityId].split(", ");
					var reInName = /[\s',]/g;
					_IG_Analytics("UA-2474779-5", "/code/weathergadget/"+aName[1].replace(reInName,"-")+"/"+aName[0].replace(reInName,"-"));
}
//------------------
//预报滚动效果
//------------------
function DayfAni(){
	$("#Container").width(80*sDays);
	//var t=3000;
	//var onepxtime = t/(80*sDays-$("#copyright").width());
	$("#Bleft").mouseover(function(e){$("#Container").animate({left:"0px"},3000,function(){
		  	$("#Bleft").css("display","none");
		  	$("#Bright").css("display","block");
		})});
	$("#Bleft").mouseout(function(e){
		  print($("#Container").css("left"));
		  $("#Container").stop();
		  if($("#Container").css("left")!="0px"){
		    $("#Bleft").css("display","block");
		    $("#Bright").css("display","block");
		  }
		});
	$("#Bright").mouseover(function(e){$("#Container").animate({left:$("#copyright").width()-80*sDays+"px"},3000,function(){
		  	$("#Bright").css("display","none");
		  	$("#Bleft").css("display","block");
		})});
	$("#Bright").mouseout(function(e){
		  print($("#Container").css("left"));
		  $("#Container").stop();
		  if($("#Container").css("left")!=$("#copyright").width()-80*sDays+"px"){
		    $("#Bleft").css("display","block");
		    $("#Bright").css("display","block");
		  }
		});
}

//------------------
//Add Calendar
//------------------
function fnaddcalendar(){
  var lang = _args()["lang"];
  if (typeof lang == "undefined") {lang = "all";}
  var s1 = oPrefs.getMsg("MSGAddCalendars");
  var s2 = oPrefs.getMsg("MSGAddCalendar");
  var url = _esc('http://weather-dnxh.appspot.com/calendar?hl='+lang+'&u='+sUnit+'&code='+aCityCodes[iCurrenCityId])
  var str = s1+'<b><a href=\"http://www.google.com/calendar/render?cid='+url+'\" target=\"_blank\">'+s2+'?</a></b>';
  fnOpenMsg(str);
}
	
//------------------
//打开菜单
//------------------
function HeadCitysIO(){
  var v = $("#urlary");
  if(v.html()==""){
    v.css("display","block");
    v.css("width",$("#nowc").width());
    var c=[];
    for(i=0;i<aCityNames.length;i++){
      c.push("<a id=\""+aCityNames[i]+"\" class=\"urlary\" onclick=\"fnLoadWeatherData('"+aCityCodes[i]+"');return false\">"+aCityNames[i]+"</a><br/>");
    }
    v.html(c.join(""));
  }else{
    v.css("display","none");
    v.html("");
  }
}
	 
//------------------
//Loading start...
//------------------
function Loadingstart(){
  //$("#panel").fadeOut(200);
  $("#loading").css("display","block"); 
  $("#loading").css("left",$("#panel").width()/2-16);
  $("#loading").css("top",$("#panel").height()/2-16);
}
	
//------------------
//Loading end...
//------------------
function Loadingend(){
  //$("#panel").fadeIn(200);
  $("#loading").css("display","none"); 
  $("#loading").css("left",-200);
  $("#loading").css("top",-200);
}
 
function init(){
  google.load("jquery", "1.3.2");
  google.load("jqueryui", "1.7.2");
  google.load('maps','3', {other_params: "sensor=false"});
  google.setOnLoadCallback(function(){  
    if(debug){
    $("#debug_div").dialog({ title: 'Debug',autoOpen: false });
    var loc = google.loader.ClientLocation;
    if (navigator.geolocation){
    	
    	//for firefox 3.5
    	navigator.geolocation.getCurrentPosition(function(position) {
	      print("Navigator Geolocation:: "+ position.coords.latitude + ',' + position.coords.longitude + "," + position.coords.accuracy);
    	                                       },function(error){
    	  print("Navigator Geolocation error:: "+error.code+", "+error.message);
    	},{timeout:15000});
    }else if(loc){
    	
    	//for Google Ajax Loader
    	print("GoogleLoader:: "+loc.latitude+","+loc.longitude);
    }else if(window.google && google.gears){
    	
    	//for Google Gears
    	try {
	    	var geo = google.gears.factory.create('beta.geolocation');
	      geo.getCurrentPosition(function(position) {
		      print("Google Gears:: "+ position.latitude + ',' + position.longitude);
	    	                                       }, function(error){
	    	  print("Google Gears error:: "+error.code+", "+error.message);
	    	},{ gearsAddressLanguage: "en", gearsRequestAddress: true, timeout: 15000 });
      }catch (e) {
    	  print('Error using Geolocation API: ' + e.message);
      }
    }else{
    	print("pls Install Google Gears!");
    }
  }
    var syndication = _args()["synd"];
    if(syndication == "open" || syndication == "pagecreator") {
      // gadget in a webpage //pagecreator //open 
      sCityNames="Nantong, China|Beiing, China";;
      sCityCodes="CHXX0101|CHXX0008";
      var cookie = readCookie("GadgetWeatherbyDnxh.cn");
      if(cookie){
        aCityNames = cookie.split("||")[0].split("|");
        aCityCodes = cookie.split("||")[1].split("|");
        sUnit  = cookie.split("||")[2];
      }else{
        aCityNames = sCityNames.split("|");
        aCityCodes = sCityCodes.split("|");
        sUnit  = "m";
      }
    }

  //载入第一个
  fnLoadWeatherData(aCityCodes[0]);
  $("#citysbutton").click(HeadCitysIO);
  $("#nowcity").click(HeadCitysIO);
  DayfAni();
  $(".ui-icon").hover(function() { $(this).addClass('ui-state-hover'); }, function() { $(this).removeClass('ui-state-hover');} );
});
} 